package com.booksystem.campuslibrarymanagementsystem.utils;

import java.security.SecureRandom;
import java.util.Base64;

public class SaltUtil {
    private SaltUtil(){}

    //盐值
    private static String Salt() {
        SecureRandom random = new SecureRandom();
        byte[] salt = new byte[8]; // 你可以根据需要调整盐值的长度
        random.nextBytes(salt);
        Base64.getEncoder().encodeToString(salt);
        // 将盐值转换为十六进制的字符串表示（可选，方便显示和存储）
        StringBuilder sb = new StringBuilder();
        for (byte b : salt) {
            sb.append(String.format("%02x", b));
        }
        String saltHex = sb.toString();
        return saltHex;
    }

    public static String saltGet(){
        return Salt();
    }

}
